<?php

namespace App\Admin\Controllers;

use App\Lazada;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class LazadaController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = 'App\Lazada';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Lazada());

        $grid->filter(function($filter){

            // 去掉默认的id过滤器
            $filter->disableIdFilter();

            // 在这里添加字段过滤器
            $filter->like('SellerName', '卖家简称');

        });

        $grid->column('id', __('ID'));
        $grid->column('SellerName', __('卖家简称'))->display(function($text) {
            return str_limit($text, 12, '...');
        });
        $grid->column('StoreName', __('店铺ID'));
        $grid->column('StoreState', __('店铺状态'));
        $grid->column('RegisteredEnterpriseName', __('注册企业名称'))->display(function($text) {
            return str_limit($text, 12, '...');
        });
        $grid->column('StoreCollectionMethod', __('店铺收款方式'));
        $grid->column('PrimaryAccount', __('店铺账号'));
        $grid->column('PrimaryPassword', __('店铺密码'))->display(function($text) {
            return str_limit($text, 12, '...');
        });
        $grid->column('PrimaryPhone', __('店铺手机号'));
        $grid->column('Category', __('品类'));
        $grid->column('StoreGroup', __('店铺分组'));
        $grid->column('StoreNotes', __('店铺备注'));

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Lazada::findOrFail($id));


        $show->field('id', __('ID'));
        $show->field('SellerName', __('卖家简称'));
        $show->field('StoreName', __('店铺ID'));
        $show->field('StoreState', __('店铺状态'));
        $show->field('RegisteredEnterpriseName', __('注册企业名称'));
        $show->field('StoreCollectionMethod', __('店铺收款方式'));
        $show->field('PrimaryAccount', __('店铺账号'));
        $show->field('PrimaryPassword', __('店铺密码'));
        $show->field('PrimaryPhone', __('店铺手机号'));
        $show->field('Category', __('品类'));
        $show->field('StoreGroup', __('店铺分组'));
        $show->field('StoreNotes', __('店铺备注'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Lazada());


        $form->text('id', __('ID'));
        $form->text('SellerName', __('卖家简称'));
        $form->text('StoreName', __('店铺ID'));
        $form->text('StoreState', __('店铺状态'));
        $form->text('RegisteredEnterpriseName', __('注册企业名称'));
        $form->text('StoreCollectionMethod', __('店铺收款方式'));
        $form->text('PrimaryAccount', __('店铺账号'));
        $form->password('PrimaryPassword', __('店铺密码'));
        $form->mobile('PrimaryPhone', __('店铺手机号'));
        $form->text('Category', __('品类'));
        $form->text('StoreGroup', __('店铺分组'));
        $form->text('StoreNotes', __('店铺备注'));

        return $form;
    }
}
